Skip to main content

Enable Your App to Deploy Template Packages

You can enable your web application to deploy Twinit Template Packages using the twinit-template-pkg node module.

This package allows you to validate template packages and deploy template packages to workspaces on Twinit.

Installation

Be sure you have followed the steps to enable installing packages from npm.twinit.dev.

npm install @dtplatform/twinit-template-pkg

twinit-template-pkg requires that you also have installed compatible versions of:

  • jszip: "^3.10.1"
  • @dtplatform/platform-api: "^5.0.0"
  • @dtplatform/iaf-script-engine: "^5.0.0"

Usage

Validate a Template Package

You can validate a template package using

import { validateTemplatePackage } from '@dtplatform/twinit-template-pkg'

async function deployTemplates(input, lbraries, ctx) {

const validationResult = await validateTemplatePackage(packageFile)

}
Parameters
packageFilea String/Array of bytes/ArrayBuffer/Uint8Array/Buffer/Blob or a Promise that resolves to a String/Array of bytes/ArrayBuffer/Uint8Array/Buffer/Blob
Returns
validationResultsa validation result object, results are returned when the first error is encountered
{
valid: <boolean> // true if the validation passed, false if it didn't
message: <string> // an error or success message
manifest: <object> // the parsed template package manifest, if validation fails this is null
}

Deploy a Template Package

You can validate a template package using

import { deployTemplatePackage } from '@dtplatform/twinit-template-pkg'

async function deployTemplates(input, lbraries, ctx) {

const { IafProj } = libraries.PlatformApi

let project = IafProj.getCurrent(ctx)

const results = await deployTemplatePackage(packageFile, project, ctx)
}
Parameters
packageFilea String/Array of bytes/ArrayBuffer/Uint8Array/Buffer/Blob or a Promise that resolves to a String/Array of bytes/ArrayBuffer/Uint8Array/Buffer/Blob
projectthe Twinit workpace/project in to which the template package should be deployed
ctxthe current Twinit ctx
Returns
deployResultsan Array&lt;string> of deployment log messages